package com.etcsoft.pagedesigner.view;

import org.eclipse.core.resources.IFile;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;

import com.etcsoft.pagedesigner.model.ProjectItem;

/**
 * @author korman21@gmail.com
 *
 */
public class ProjectFilter extends ViewerFilter {
    private StructuredViewer viewer;
    private String projectName;

    public ProjectFilter(StructuredViewer viewer, String projectName) {
        this.viewer = viewer;
        this.projectName = projectName;
    }

    @Override
    public boolean select(Viewer viewer, Object parentElement, Object element) {
        if (element instanceof ProjectItem) {
            ProjectItem projectItem = (ProjectItem) element;
            if (!(projectItem.getResource() instanceof IFile)) {
                String projectName = projectItem.getResource().getProject().getName();
                if (this.projectName.equals(projectName)) {
                    return true;
                }
            }
        }
        return false;
    }


}
